package com.gml.design.factory.optimize;

import com.gml.design.factory.optimize.impl.CardCommodity;
import com.gml.design.factory.optimize.impl.CouponCommodity;
import com.gml.design.factory.optimize.impl.GoodsCommodity;

/**
 * 工厂
 */
public class StoreFactory {

    public ICommodity getCommodity(Integer commodityType){
        if (null == commodityType) return null;
        if (1 == commodityType) return new CouponCommodity();
        if (2 == commodityType) return new GoodsCommodity();
        if (3 == commodityType) return new CardCommodity();
        throw new RuntimeException("不存在的奖品服务类型");
    }

    /**
     * 奖品类信息方式实例化
     * @param clazz 奖品类
     * @return      实例化对象
     */
    public ICommodity getCommodity(Class<? extends ICommodity> clazz) throws IllegalAccessException, InstantiationException {
        if (null == clazz) return null;
        return clazz.newInstance();
    }

}
